package com.qf58.search.aspect;


import com.qf58.search.exception.APIException;
import com.qf58.search.exception.ServiceException;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Description:
 * User: zhubo
 * Date: 2017-06-18
 * Time: 10:25
 */
@Component
@Aspect
public class ServiceExceptionInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(ServiceExceptionInterceptor.class);

    @AfterThrowing(throwing="ex",pointcut="execution(* com.qf58.crm.extend.module.service.impl.*.*(..))")
    public Object handle(ServiceException ex){
        logger.info("intercept ServiceException:{}",ex);
        System.out.println("defined Exception "+ex.toString());
        throw new APIException(ex.getCode(),ex.getMsg());
    }
}
